import json
import pymysql

conn = pymysql.connect(
    host='localhost',  # mysql服务器地址
    port=3306,  # 端口号
    user='root',  # 用户名
    passwd='root',  # 密码
    db='journal',  # 数据库名称
    charset='utf8',  # 连接编码，根据需要填写
)
cur = conn.cursor()  # 创建并返回游标
path = r'../cssci/19-中国图书馆学报.json'
f = open(path, 'r',encoding='utf-8')
for i in f.readlines():
    jsonstr = json.loads(i)
    for j in jsonstr['contents']:
        id = j['id']
        sno = j['sno']
        authors = j['authors']
        authors_address = j['authors_address']
        authors_jg = j['authors_jg']
        blpm = j['blpm']
        byc = j['byc']
        juan = j['juan']
        lypm = j['lypm']
        lypmp = j['lypmp']
        nian = j['nian']
        qi = j['qi']
        qkmc = j['qkmc']
        wzlx = j['wzlx']
        xkdm1 = j['xkdm1']
        xkfl1 = j['xkfl1']
        xmlb = j['xmlb']
        yjdm = j['yjdm']
        ym = j['ym']
        catation = ''
        authorsDetail = ''
        print(id)
        sql = '''insert into `中国图书馆学报` (id,sno,authors,authors_address,authors_jg,blpm,byc,juan,lypm,lypmp,nian,qi,qkmc,wzlx,xkdm1,xkfl1,xmlb,yjdm,ym,catation,authorsDetail) values ("''' + id + '''","''' + sno + '''","''' + authors + '''","''' + authors_address + '''","''' + authors_jg + '''","''' + blpm + '''","''' + byc + '''","''' + juan + '''","''' + lypm + '''","''' + lypmp + '''","''' + nian + '''","''' + qi + '''","''' + qkmc + '''","''' + wzlx + '''","''' + xkdm1 + '''","''' + xkfl1 + '''","''' + xmlb + '''","''' + yjdm + '''","''' + ym +'''","''' + catation + '''","''' + authorsDetail + '''");'''
        print(sql)
        try:
            cur.execute(sql)
            conn.commit()
        except Exception as e:
            continue
conn.close()